cmake_minimum_required(VERSION 3.5)
set(CMAKE_C_COMPILER    riscv32-unknown-elf-gcc)
set(CMAKE_CXX_COMPILER  riscv32-unknown-elf-g++)


set(STARTUP_DIR ./env)

project(simple)
set(CMAKE_CXX_STANDARD 11)

enable_language(C)
enable_language(ASM)

set(SOURCE_FILES
    ./main.c
    ./crtm.S
    )

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
#for compiler
set(CMAKE_C_FLAGS "-march=rv32i -mabi=ilp32")
set(CMAKE_ASM_FLAGS "-march=rv32i -mabi=ilp32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --specs=nano.specs")      #uncomment this for using nano stdlib
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--no-relax")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--gc-sections")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcmodel=medany")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -T ${PROJECT_SOURCE_DIR}/default.ld")

add_executable(${BIN_NAME}.elf ${SOURCE_FILES})

